package com.outdoor.server.controller.admin;

import com.outdoor.common.result.PageResult;
import com.outdoor.common.result.Result;
import com.outdoor.pojo.dto.UserPageQueryDTO;
import com.outdoor.pojo.dto.UserPermissionDTO;
import com.outdoor.pojo.entity.User;
import com.outdoor.server.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/user")
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 分页查询用户信息
     * @param userPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> page (UserPageQueryDTO userPageQueryDTO) {
        log.info("userPageQueryDTO:{}", userPageQueryDTO);
        PageResult pageResult = userService.page(userPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据id查询用户信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<User> getUserById(@PathVariable Long id) {
        log.info("id:{}", id);
        User user = userService.getUserById(id);
        return Result.success(user);
    }
    /**
     * 更新用户权限
     * @param userPermissionDTO
     * @return
     */
    @PutMapping("/permission")
    public Result<String> updateUserPermission(@RequestBody UserPermissionDTO userPermissionDTO) {
        log.info("更新用戶权限：{}", userPermissionDTO);
        userService.updateUserPermission(userPermissionDTO);
        return Result.success();
    }
}
